package cn.flant.log.adapter;

public class JDK14Adapter extends LogAdapter {
	private java.util.logging.Logger log = null;

	protected JDK14Adapter(String name) {
		super(name);
		log = java.util.logging.LogManager.getLogManager().getLogger(name);
		if (log == null) {
			throw new IllegalStateException("JDK14 logger is not available");
		}
	}

	@Override
	public void debug(Object msg) {
		if (DEBUG < level) {
			return;
		}
		log.log(java.util.logging.Level.FINE, msg == null ? "" : msg.toString());

	}

	@Override
	public void debug(Object msg, Throwable t) {
		if (DEBUG < level) {
			return;
		}
		log.log(java.util.logging.Level.FINE, msg == null ? "" : msg.toString(), t);

	}

	@Override
	public void error(Object msg) {
		if (ERROR < level) {
			return;
		}
		log.log(java.util.logging.Level.SEVERE, msg == null ? "" : msg.toString());

	}

	@Override
	public void error(Object msg, Throwable t) {
		if (ERROR < level) {
			return;
		}
		log.log(java.util.logging.Level.SEVERE, msg == null ? "" : msg.toString(), t);
	}

	@Override
	public void fatal(Object msg) {
		if (FATAL < level) {
			return;
		}
		log.log(java.util.logging.Level.SEVERE, msg == null ? "" : msg.toString());
	}

	@Override
	public void fatal(Object msg, Throwable t) {
		if (FATAL < level) {
			return;
		}
		log.log(java.util.logging.Level.SEVERE, msg == null ? "" : msg.toString(), t);
	}

	@Override
	public void info(Object msg) {
		if (INFO < level) {
			return;
		}
		log.log(java.util.logging.Level.INFO, msg == null ? "" : msg.toString());

	}

	@Override
	public void info(Object msg, Throwable t) {
		if (INFO < level) {
			return;
		}
		log.log(java.util.logging.Level.INFO, msg == null ? "" : msg.toString(), t);

	}

	@Override
	public void warn(Object msg) {
		if (WARN < level) {
			return;
		}
		log.log(java.util.logging.Level.WARNING, msg == null ? "" : msg.toString());

	}

	@Override
	public void warn(Object msg, Throwable t) {
		if (WARN < level) {
			return;
		}
		log.log(java.util.logging.Level.WARNING, msg == null ? "" : msg.toString(), t);
	}

}
